package de.hawhamburg.shc.controller;

import java.util.Locale;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.content.Context;

import de.hawhamburg.smarthomecontroller.R;
import de.hawhamburg.shc.controller.Settings;
import de.hawhamburg.shc.fragments.RoomListFragment;
import de.hawhamburg.shc.fragments.SpeechFragment;

	/*
	 * A FragmentPagerAdapter that returns a fragment corresponding to
	 * one of the sections/tabs/pages.
	 */
	public class SectionsPagerAdapter extends FragmentPagerAdapter {
		Settings settings;
		public SectionsPagerAdapter(FragmentManager fm, Settings settings) {
			super(fm);
			this.settings = settings;
		}
		
		public Fragment getItem(int position) {
			// getItem is called to instantiate the fragment for the given page.
			switch (position) {
			case 0:
				RoomListFragment fragment = new RoomListFragment();
				return fragment;		
			case 1:
				Fragment fragment2 = new SpeechFragment();				
				return fragment2;
			}
			return null;
		}
		
		@Override
		public int getCount() {
			// Show 2 total pages.
			return 2;
		}
		
		/*
		 * set the Tab Title
		 */
		@Override
		public CharSequence getPageTitle(int position) {
			Context context = settings.context;
			Locale l = Locale.getDefault();
			
			switch (position) {
			case 0:
				return context.getString(R.string.title_section1).toUpperCase(l);
			case 1:
				return context.getString(R.string.title_section2).toUpperCase(l);
			}
			return null;
		}

	}